#include <string>
#include <vector>
#include <unordered_map>
#include <array>

using namespace std;

class Solution {
public:

    //将句子排序
    string sortSentence(string s) {
        array<string, 9> arr;
        string tmp;
        int count = 0;
        for (auto& ch : s)
        {
            if (ch == ' ')
                continue;
            if (isdigit(ch))
            {
                arr[ch-'0'-1] = tmp;
                tmp.clear();
                ++count;
            }
            else 
            {
                tmp += ch;
            }
        }
        string ans = arr[0];
        for (size_t i = 1; i<count; ++i)
        {
            ans += " " + arr[i];
        }
        return ans;
    }

    //最长和谐子序列
    int findLHS(vector<int>& nums) {
        unordered_map<int, int> _hash;
        for (int num : nums)
        {
            ++_hash[num];
        }

        int maxLenth = 0;
        for (auto& [key, val] : _hash)
        {
            if (_hash.count(key + 1) > 0)
            {
                maxLenth = max(maxLenth, val + _hash[key+1]);
            }
        }

        return maxLenth;
    }
};